from surprise import Dataset
from surprise import Reader
from surprise import BaselineOnly, KNNBasic, NormalPredictor
from surprise import accuracy
from surprise.model_selection import KFold, split
from surprise import SVD,SVDpp
#import pandas as pd

# 数据读取
reader = Reader(line_format='user item rating timestamp', sep=',', skip_lines=1)
data = Dataset.load_from_file('./ratings.csv', reader=reader)
#rain_set = data.build_full_trainset()
train_s,test_s = split.train_test_split(data, train_size=0.8)

algo1 = SVD()
algo2 = SVD(biased = False)
algo3 = SVDpp()

print('考虑用户偏好，SVDbias结果')
algo1.fit(train_s)
pre = algo1.predict(test_s)
accuracy.rmse(pre,verbose=True)

print('FunkSVD结果')
algo2.fit(train_s)
pre = algo2.predict(test_s)
accuracy.rmse(pre,verbose=True)

print('考虑用户偏好，考虑用户的隐式反馈，SVD++结果')
algo3.fit(train_s)
pre = algo3.predict(test_s)
accuracy.rmse(pre,verbose=True)